<!--
/**************************************************
* @(#)checkManufacture.jsp
*
* Copyright (c) 2005 Hitrust Technology Inc.
* Developed by SDC, Hitrust.
* All Rights Reserved.
*
* Modify History:
*  v1.00, 2006/02/08, SimonyiPeng
*  1) first release
/**************************************************
-->

<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ page import="com.hitrust.gs.business.GSManufactureProcessor"%>
<%@ page import="com.hitrust.gs.bean.GSManufactureBean"%>
<%@ include file="../../common.jsp" %>
<SCRIPT language="JavaScript" src="<%=root%>/js/common.js"></SCRIPT>
<SCRIPT language="JavaScript" src="<%=root%>/js/string.js"></SCRIPT>


<%
LoginContext context=(LoginContext)session.getAttribute(GSBaseConstants.LOGIN);
boolean isManufactureExist = false;
GSManufactureBean bean = null;
String rowNum = request.getParameter("rownum");
String concentricityId = request.getParameter("concentricityid");
String deptid=request.getParameter("deptid");
GSUniteGwProcessor unitepro=new GSUniteGwProcessor();
ArrayList warelist=unitepro.getBzwzAndTmpWareHouse(context.getLoginWarehouseCode());
GSManufactureProcessor processor = new GSManufactureProcessor ();
GSManufactureBean tBean = processor.getManufactureForOrderInput(concentricityId,warelist);
ArrayList provList = processor.getProviderSimpleByconcentricityid(concentricityId,deptid);
System.out.print(provList.size()+"=========");
String manufactureId = null;
String manufactureName = null;
String quantUnit = null;
String manufactureUnitPrice = null;
String spec = null;
String type = null;
String brand = null;
String quantunit = null;
String period = null;
String mode=null;
boolean bool = false;
String  msg="集中编码输入不正确!";
if(tBean != null && provList != null && provList.size() != 0){
	
	concentricityId = tBean.getGs_concentricity();
	manufactureName = tBean.getGs_manufacture_name();
	quantUnit = tBean.getGs_quant_unit();
	manufactureUnitPrice = StringUtils.formatEDouble(tBean.getGs_manufacture_unitprice(),4);
	spec = StringUtils.escapeXML(tBean.getGs_manufacture_spec());
	type = tBean.getGs_manufacture_type();
	quantunit = tBean.getGs_quant_unit();
	brand = tBean.getGs_manufacture_brand();
	period = tBean.getGs_quality_assure_period();
	mode=tBean.getGs_balance_mode();
	bool = true;
	GSOrderCategoryDAO dao= new GSOrderCategoryDAO();	
    if(dao.queryProductCategory(concentricityId,tBean.getGs_provider_id())){
    	bool = true;
    	if(dao.queryProductByOrderCategory(concentricityId,tBean.getGs_provider_id(),deptid)){
    		msg="该集中编码产品对应的供应商不是仓库指定的！";
    		bool = false;
    	}else{
    		if(dao.queryProductBrandOfHave()){
    			if(dao.queryProductBrandIsCenter(concentricityId)){
    				if(dao.queryProductBrand(concentricityId,deptid)){
						msg="不能申购，请联系物资公司！";
						bool = false;
					}
    			}
    		}
    	}
    }else{
		if(dao.queryProductBrandOfHave()){
			if(dao.queryProductBrandIsCenter(concentricityId)){
				if(dao.queryProductBrand(concentricityId,deptid)){
					msg="不能申购，请联系物资公司！";
					bool = false;
				}
			}
		}
	}
	
}else if(tBean==null){
    //查询该产品详细信息
    tBean=processor.getManufInfoByConcentricityId(concentricityId);
    if(tBean!=null){
        if("0".equals(tBean.getGs_validity())){
            msg="该集中编码产品无效或不可采购！";
        }else if("1".equals(tBean.getGs_validity())){
            if(provList == null || provList.size() == 0){
                msg="该集中编码产品供应商状态无效！";
            }
        }
    }
} 
%>


<script language='javascript'>
	function onsubmit(){

		if(<%=bool%>){

			
			var provId;	
			var provShortName;
			var concentricityId;
			var manufactureId;
			var unitPrice;
            var balancemode;
            var s="";
				var providerlist = parent.document.getElementById("providerid");
				var pricebuffer = "";
				
				var pros = parent.document.getElementById("providerid"+<%=rowNum%>);
				for(;;)
				{
					 if(pros.options.length==1) break ;
					 pros.options.remove(pros.options.length-1);
				}
			<%
				for(int x=0;x<provList.size();x++){
			%>
					provId = "<%=((String[])provList.get(x))[0]%>";
					provShortName = "<%=((String[])provList.get(x))[1]%>";
					concentricityId = "<%=((String[])provList.get(x))[2]%>";
					manufactureId = "<%=((String[])provList.get(x))[3]%>";
					unitPrice = "<%=((String[])provList.get(x))[4]%>";
                    balancemode = "<%=((String[])provList.get(x))[5]%>";
                    if(balancemode=='<%=GSBaseConstants.BALANCE_MODE1%>'){
                        s="<%=DefineDic.getBalanceMode(GSBaseConstants.BALANCE_MODE1)%>";
                    }else{
                        s="<%=DefineDic.getBalanceMode(GSBaseConstants.BALANCE_MODE2)%>";
                    }
					parent.document.getElementById("manufactureid"+<%=rowNum%>).value = manufactureId;
					var provid = parent.document.getElementById("providerid"+<%=rowNum%>);
					var tempoption=new Option(provShortName,provId);
					provid.options[provid.length] = tempoption;					
					pricebuffer = pricebuffer + provId + ":" + unitPrice + ":" + concentricityId + ":" + manufactureId +":"+balancemode+":"+s+"|";
					parent.document.getElementById("pricebuffer"+<%=rowNum%>).value = pricebuffer;
			<%
				}
			%>

						
			parent.document.getElementById("concentricityid"+<%=rowNum%>).value = '<%=concentricityId%>';
			parent.document.getElementById("manufacturename"+<%=rowNum%>).innerHTML="<div align='center' class='txt_content'><a href='<%=response.encodeURL(root+"/A110104.do")%>?concentricityId="+"<%=concentricityId%>"+"' target='_blank'>"+"<%=manufactureName%>"+"</a></div>";


			parent.document.getElementById("spec"+<%=rowNum%>).innerHTML = "<div align='center' class='txt_content'>"+'<%=spec%>'+"</div>";
			parent.document.getElementById("type"+<%=rowNum%>).innerHTML = "<div align='center' class='txt_content'>"+'<%=type%>'+"</div>";
			parent.document.getElementById("brand"+<%=rowNum%>).innerHTML = "<div align='center' class='txt_content'>"+'<%=brand%>'+"</div>";
			parent.document.getElementById("period"+<%=rowNum%>).innerHTML = "<div align='center' class='txt_content'>"+'<%=period%>'+"</div>";
			parent.document.getElementById("quantunit"+<%=rowNum%>).innerHTML = "<div align='center' class='txt_content'>"+'<%=quantunit%>'+"</div>";

			//为确认提示预备值
			if(parent.document.getElementById("manufacturename_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturename_"+<%=rowNum%>).value = "<%=manufactureName%>";
			if(parent.document.getElementById("manufacturespec_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturespec_"+<%=rowNum%>).value = "<%=spec%>";
			if(parent.document.getElementById("manufacturetype_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturetype_"+<%=rowNum%>).value = "<%=type%>";
			if(parent.document.getElementById("manufacturebrand_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturebrand_"+<%=rowNum%>).value = "<%=brand%>";
			if(parent.document.getElementById("period_"+<%=rowNum%>)!=null)
				parent.document.getElementById("period_"+<%=rowNum%>).value = "<%=period%>";	
			if(parent.document.getElementById("manufacturequantunit_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturequantunit_"+<%=rowNum%>).value = "<%=quantunit%>";

		}
		else
		{
			var pros = parent.document.getElementById("providerid"+<%=rowNum%>);
			for(;;)
			{
				 if(pros.options.length==1) break ;
				 pros.options.remove(pros.options.length-1);
			}
				
			parent.document.getElementById("concentricityid"+<%=rowNum%>).value = '';
			parent.document.getElementById("manufacturename"+<%=rowNum%>).innerHTML = '';

			parent.document.getElementById("spec"+<%=rowNum%>).innerHTML = '';
			parent.document.getElementById("type"+<%=rowNum%>).innerHTML = '';
			parent.document.getElementById("brand"+<%=rowNum%>).innerHTML = '';
			parent.document.getElementById("period"+<%=rowNum%>).innerHTML = '';
			parent.document.getElementById("quantunit"+<%=rowNum%>).innerHTML = '';

			//为确认提示清理预备值
			if(parent.document.getElementById("manufacturename_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturename_"+<%=rowNum%>).value = "";
			if(parent.document.getElementById("manufacturespec_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturespec_"+<%=rowNum%>).value = "";
			if(parent.document.getElementById("manufacturetype_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturetype_"+<%=rowNum%>).value = "";
			if(parent.document.getElementById("manufacturebrand_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturebrand_"+<%=rowNum%>).value = "";
			if(parent.document.getElementById("period_"+<%=rowNum%>)!=null)
				parent.document.getElementById("period_"+<%=rowNum%>).value = "";	
			if(parent.document.getElementById("manufacturequantunit_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturequantunit_"+<%=rowNum%>).value = "";
						
			alert('<%=msg%>');
		}

		return  false;
	}
</script>
<%@page import="system.LoginContext"%>
<%@page import="com.hitrust.gs.business.GSUniteGwProcessor"%>
<html>
<body onLoad="onsubmit();"></body>
</html>


